﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace yule.CodeBuilder.Controllers
{
    public class RegionController : BaseController
    {
        //
        // GET: /Region/

        public ActionResult Index()
        {
            return View(this.ServiceContext.CreateService<yule.IService.Sys.IRegion>().GetRegionList());
        }

        public ActionResult Edit(string id)
        {
            ViewData.Model = this.ServiceContext.CreateService<yule.IService.Sys.IRegion>().GetRegion(id);

            if (this.Request.IsAjaxRequest())
            {
                return this.PartialView();
            }
            else
            {
                return this.View();
            }
        }

        public ActionResult DoEdit(yule.Model.Sys.Region model)
        {
            if (model != null)
            {
                yule.IService.Sys.IRegion regionSrv = this.ServiceContext.CreateService<yule.IService.Sys.IRegion>();
                yule.Model.Sys.Region m = regionSrv.GetRegion(model.Id);
                if (this.TryUpdateModel<yule.Model.Sys.Region>(m) == true)
                {
                    if (regionSrv.Update(m) == true)
                    {
                        //成功
                    }
                    else
                    {
                        //失败
                    }
                }
            }
            return this.RedirectToAction("Index");
        }

        public ActionResult Delete(string id)
        {
            return this.View("Index");
        }

        public ActionResult Details(string id)
        {
            ViewData.Model = this.ServiceContext.CreateService<yule.IService.Sys.IRegion>().GetRegion(id);
            if (this.Request.IsAjaxRequest() == true)
            {
                return this.PartialView();
            }
            else
            {
                return this.View();
            }
        }

    }
}